package fr.loof.fonzie;

import javax.persistence.EntityManager;
import javax.persistence.LockModeType;
import javax.persistence.PersistenceContext;

public class Fonzie
{
    private static Fonzie instance = new Fonzie();

    @PersistenceContext
    private EntityManager entityManager;

    public static Fonzie instance()
    {
        return instance;
    }

    public boolean contains( Object entity )
    {
        return entityManager.contains( entity );
    }

    public <T> T find( Class<T> entityClass, Object primaryKey )
    {
        return entityManager.find( entityClass, primaryKey );
    }

    public <T> T getReference( Class<T> entityClass, Object primaryKey )
    {
        return entityManager.getReference( entityClass, primaryKey );
    }

    public void lock( Object entity, LockModeType lockMode )
    {
        entityManager.lock( entity, lockMode );
    }

    public <T> T merge( T entity )
    {
        return entityManager.merge( entity );
    }

    public void persist( Object entity )
    {
        entityManager.persist( entity );
    }

    public void refresh( Object entity )
    {
        entityManager.refresh( entity );
    }

    public void remove( Object entity )
    {
        entityManager.remove( entity );
    }

    public void setEntityManager( EntityManager entityManager )
    {
        this.entityManager = entityManager;
    }

}
